<?php
/**
 * Created by PhpStorm.
 * User: sykbxc
 * Date: 2019/4/3
 * Time: 16:50
 */

namespace App\Http\Requests;

use App\Exceptions\AdminValidationException;
use App\Response\AdminRep;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;

class BaseRequest extends FormRequest
{
    use AdminRep;

    protected function failedValidation(Validator $validator)
    {
        $msg = $validator->errors()->getMessages();
        $msg = $this->arr_to_str(array_values($msg));
        throw new AdminValidationException($msg);
    }

    function arr_to_str($arr) {
        $t ='' ;
        foreach ($arr as $v) {
            $v = join(",",$v); // 可以用implode将一维数组转换为用逗号连接的字符串，join是别名
            $temp[] = $v;
        }
        foreach ($temp as $v) {
            $t.=$v;
        }
        return $t;
    }

}